﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using MethodWorx.CMS.TemplateLanguage.Properties;
using MethodWorx.CMS.TemplateLanguage.Design;
using System.Web.UI.WebControls;

namespace MethodWorx.CMS.TemplateLanguage.Parsers.Html
{
    public class TextArea : IParser, IDesignable
    {
        public TextArea()
        {
            this.Width = 200;
        }

        [Property(Alias="Name")]
        public string ControlName { get; set; }

        [Property]
        public string Value { get; set; }

        [UnitProperty(Unit="px")]
        public int Width { get; set; }

        public object Parse(Web.CmsRequestContext context, IEnumerable<object> stack, Dictionary<string, object> parameters)
        {
            return "<textarea name=\"" + this.ControlName +"\">" + (HttpContext.Current.Request[this.ControlName] ?? this.Value) + "</textarea>";
        }

        public string Name
        {
            get { return "textarea"; }
        }

        public string Namespace
        {
            get { return "html"; }
        }

        public string[] Parameters
        {
            get { return new string[] { "name", "value" }; }
        }

        public void Design(IDesigner designer)
        {
            designer.AddControl("Html:TextArea")
                .AddContentBeforeChildren(
                    "<span style=\"display:inline-block;width:" + this.Width  + "px;height:45px;padding:2px;background-color:white;border:1px solid silver\">" +
                    this.Value + "</span>");
        }
    }
}
